package com.nbst.service.base.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nbst.comnutil.LogOut;
import com.nbst.comnutil.NormalResult;
import com.nbst.dao.mapper.mes.DeskMapper;
import com.nbst.model.base.Menu;
import com.nbst.service.base.IDeskService;

/**
 * @ClassName: IDeskServiceImpl
 * @Description:
 * @author 兵
 * @date 2017-8-25
 * 
 */
@Service
public class DeskServiceImpl implements IDeskService {
	@Autowired
	DeskMapper deskmapper;

	@Autowired
	LogOut logout;

	@Override
	public NormalResult deleteByuId(Integer id) {
		NormalResult result = new NormalResult();
		int num = 0;
		try {
			num = deskmapper.deleteByPrimaryKey(id);
			if (num == 1) {
				result.setCode("0000");
				result.setMessage("删除成功");
			}
		} catch (Exception e) {
			logout.error(e);
			result.setCode("9999");
			result.setMessage("删除失败");
			result.setDataset(e);
		}
		return result;
	}

	@Override
	public NormalResult insertSelective(Map<String,Object> record) {
		NormalResult result = new NormalResult();
		int num = 0;
		try {
			num = deskmapper.insertSelective(record);
			if (num == 1) {
				result.setCode("0000");
				result.setMessage("新增成功");
			}
		} catch (Exception e) {
			logout.error(e);
			result.setCode("9999");
			result.setMessage("新增失败");
			result.setDataset(e);
		}
		return result;
	}

	@Override
	public List<Menu> findByCondition(Map<String,Object> map) {
		List<Menu> list = new ArrayList<Menu>();
		try {
			list = deskmapper.findByCondition(map);
		} catch (Exception e) {
			logout.error(e);
		}
		return list;
	}

	@Override
	public NormalResult updateByPrimaryKeySelective(Map<String,Object> map) {
		NormalResult result = new NormalResult();
		int num = 0;
		try {
			num = deskmapper.updateByPrimaryKeySelective(map);
			if (num == 1) {
				result.setCode("0000");
				result.setMessage("修改成功");
			} else {
				result.setCode("9999");
				result.setMessage("修改失败");
			}
		} catch (Exception e) {
			logout.error(e);
			result.setCode("9999");
			result.setMessage("出错了,刷新后再试试吧");
			result.setDataset(e);
		}
		return result;
	}

	@Override
	public NormalResult deleteByUserIdAndPid(Map<String,Object> record) {
		NormalResult result = new NormalResult("9999", "操作失败");
		deskmapper.deleteByPId(record);
		result.setCode("0000");
		result.setMessage("操作成功");
		return result;
	}

}